function throttle(fn,delay){
    let lastTime
    let timer
    delay||(delay=300)
    return function(arguments){
        let that=this
        let args=arguments
        let nowTime=+new Date()
        if(lastTime&&nowTime<lastTime+delay){
            clearTimeout(timer)
            timer=setTimeout(() => {
                lastTime=nowTime
                fn.apply(that,args)
            }, delay);
        }else{
            lastTime=nowTime
            fn.apply(that,args)
        }
    }
}

let btn=document.querySelector("#btn")
btn.addEventListener('click',throttle(function(){
    console.log('clicked')
},1000))
